const componentMapping = {
  form: 'AForm',
  formItem: 'AFormItem',
  input: 'AInput',
  number: 'AInputNumber',
  textarea: 'ATextarea',
  row: 'ARow',
  col: 'ACol',
  button: 'AButton',
  select: 'ASelect',
  selectV2: 'ASelectV2',
  selectOption: 'ASelectOption',
  switch: 'ASwitch',
  time: 'ATimePicker',
  timeSelect: 'TAimeSelect',
  date: 'ADatePicker',
  dateTime: 'ADatePicker',
  range: 'ARangePicker',
  radioGroup: 'ARadioGroup',
  radio: 'ARadio',
  checkboxGroup: 'ACheckboxGroup',
  checkbox: 'ACheckbox',
  cascader: 'ACascader',
  rate: 'ARate',
  slider: 'ASlider',
  transfer: 'ATransfer',
  upload: 'AUpload',
  avatar: 'AAvatar',
  badge: 'ABadge',
  color: 'AColorPicker',
};

const emitMapping = {
  'update:value': [
    'input',
    'textarea',
    'select',
    'number',
    'selectV2',
    'time',
    'timeSelect',
    'date',
    'dateTime',
    'radioGroup',
    'radio',
    'checkboxGroup',
    'checkbox',
    'cascader',
    'rate',
    'slider',
    'transfer',
    'color',
    'range',
  ],
  'update:checked': ['switch'],
};

const placeholderMapping = {
  input: (label: string) => '请输入' + label,
  checkboxGroup: (label: string) => '请选择' + label,
  checkbox: (label: string) => '请选择' + label,
  radioGroup: (label: string) => '请选择' + label,
  radio: (label: string) => '请选择' + label,
  textarea: (label: string) => '请输入' + label,
  search: (label: string) => '请选择' + label,
  number: (label: string) => '请输入' + label,
  select: (label: string) => '请选择' + label,
  selectV2: (label: string) => '请选择' + label,
  date: (label: string) => '请选择' + label,
  dateTime: (label: string) => '请选择' + label,
  time: (label: string) => '请选择' + label,
  timeSelect: (label: string) => '请选择' + label,
  cascader: (label: string) => '请选择' + label,
  range: () => ['开始时间', '结束时间'],
  monthRange: () => ['开始时间', '结束时间'],
  month: (label: string) => '请选择' + label,
};

const modelMapping = {
  switch: 'checked',
};

const defaultValueMapping = {
  checkboxGroup: [],
  cascader: [],
};

const defaultRequiredRuleMapping = {
  '*'(config: { [key: string]: any }, message: string | string[]) {
    if (config.required) {
      return [
        {
          required: true,
          message: Array.isArray(message) ? message.join('-') : message,
          trigger: 'change',
        },
      ];
    }
    return [];
  },
};
export default {
  componentMapping,
  emitMapping,
  formMapping: {
    prop: 'name',
  },
  placeholderMapping,
  modelMapping,
  defaultValueMapping,
  defaultRequiredRuleMapping,
};
